<script>
import { getToken } from '@/utils/auth'
import { requestGet } from '@/api/system/common'
import DefaultLiveBosMoreBody from '@/livebos/container/more/DefaultLiveBosMoreBody.vue'

export default {
  name: 'DefaultMore',
  components: { DefaultLiveBosMoreBody },
  data() {
    return {
      dialog: false,
      loading: true,
      isLiveBos: false
    }
  },
  created() {
    this.$bus.on('openMore', this.open)
  },
  beforeDestroy() {
    this.$bus.off('openMore')
  },
  methods: {
    // 执行打开更多页面操作
    open(data) {
      if (data.dkfs === 1) { // 采用固定模版方式打开
        if (data.isLiveBos) {
          this.isLiveBos = true
          this.dialog = true
          this.initTemp(data.id)
        } else {
          window.open('/uc/more?temp=' + data.id + '&mid=' + data.parentId, '_self')
        }
      }
      if (data.dkfs === 2 && data.url !== undefined && data.url !== null && data.url !== '') {
        window.open(data.url, '_blank')
      }
    },
    initTemp(mid) {
      let url = 'rest/api/guest/temp/v2/column/analysis/obj'
      if (getToken()) {
        url = 'rest/api/temp/v2/column/analysis/obj'
      }
      requestGet(url, { cid: mid })
        .then(res => {
          const { data } = res
          data.isBack = false
          this.$bus.emit('moreTemp', data)
        }).catch(() => {
          this.$bus.emit('moreTemp', null)
        })
    },
    close() {
      this.dialog = false
    }
  }
}
</script>
<template>
  <el-dialog
    v-if="isLiveBos"
    :fullscreen="true"
    :show-close="false"
    :visible.sync="dialog"
  >
    <div slot="title" class="custom-header">
      <div class="dialog-button">
        <el-button type="primary" @click="close">
          返回<i class="el-icon-arrow-right el-icon-caret-right" />
        </el-button>
      </div>
    </div>
    <default-live-bos-more-body />
  </el-dialog>
</template>
<style scoped lang="scss">
.custom-header {
  width: 100%;
  height: 50px;
  display: flex;
  flex-flow: row nowrap;
  justify-content: right;
  align-items: center;
  padding: 0 20px;
  box-sizing: border-box;
  box-shadow: 0 2px 4px rgba(0, 0, 0, .12), 0 0 6px rgba(0, 0, 0, .04);
  .dialog-title {
    font-size: 1.1rem;
    font-weight: bold;
  }
}
</style>
